<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>注册 - {:sysconfig('im','title')}</title>
  <script src="/qstatic/js/layui.js"></script>
  <link rel="stylesheet" href="/qstatic/js/css/layui.css" />
  <script src="/qstatic/js/jquery-1.9.1.min.js"></script>
</head>
<body>
<style>
.demo-reg-container{width: 320px; margin: 21px auto 0;}
.demo-reg-other .layui-icon{position: relative; display: inline-block; margin: 0 2px; top: 2px; font-size: 26px;}
</style>
<div class="layui-form">
  <div class="demo-reg-container">
      <div style="margin: 2.5rem 0rem 0rem 0rem;font-size: 2rem;color: #16baaa;">注册</div>
      <div style="margin: 0rem 0rem 1rem 0rem;font-size: 1rem;color: #999;">REGISTER</div>
    
    {if sysconfig('sms','smsstatus') == "1"}
    <div class="layui-form-item">
      <div class="layui-row">
        <div class="layui-col-xs7">
          <div class="layui-input-wrap">
            <div class="layui-input-prefix">
              <i class="layui-icon layui-icon-cellphone"></i>
            </div>
            <input type="text" id="account" value="" lay-verify="required|phone" placeholder="手机号" lay-reqtext="请填写手机号" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-col-xs5">
          <div style="margin-left: 11px;">
            <a onclick="sendcode()"><button type="button" class="layui-btn layui-btn-fluid layui-btn-primary" lay-on="reg-get-vercode" id="scode">获取验证码</button></a>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-wrap">
        <div class="layui-input-prefix">
          <i class="layui-icon layui-icon-vercode"></i>
        </div>
        <input type="text" id="code" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input">
      </div>
    </div>
    {else /}
    <div class="layui-form-item">
      <div class="layui-input-wrap">
        <div class="layui-input-prefix">
          <i class="layui-icon layui-icon-cellphone"></i>
        </div>
        <input type="text" id="account" value="" lay-verify="required|phone" placeholder="手机号" lay-reqtext="请填写手机号" autocomplete="off" class="layui-input">
      </div>
    </div>
    {/if}
   
   <div class="layui-form-item">
      <div class="layui-input-wrap">
        <div class="layui-input-prefix">
          <i class="layui-icon layui-icon-username"></i>
        </div>
        <input type="text" id="nickname" value="" lay-verify="required" placeholder="昵称" autocomplete="off" class="layui-input" lay-affix="clear">
      </div>
    </div> 
    
    <div class="layui-form-item">
      <div class="layui-input-wrap">
        <div class="layui-input-prefix">
          <i class="layui-icon layui-icon-password"></i>
        </div>
        <input type="password" id="password" value="" lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input" lay-affix="eye">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-wrap">
        <div class="layui-input-prefix">
          <i class="layui-icon layui-icon-password"></i>
        </div>
        <input type="password" id="password2" value="" lay-verify="required|confirmPassword" placeholder="确认密码" autocomplete="off" class="layui-input" lay-affix="eye">
      </div>
    </div>

    {if sysconfig('invite','istatus') == "1"}
   <div class="layui-form-item">
      <div class="layui-input-wrap">
        <div class="layui-input-prefix">
          <i class="layui-icon layui-icon-vercode"></i>
        </div>
        <input type="text" id="yqcode" value="" placeholder="邀请码,可空" autocomplete="off" class="layui-input" lay-affix="clear">
      </div>
    </div> 
    {/if}
                            
    <!--<div class="layui-form-item">-->
    <!--  <input type="checkbox" name="agreement" lay-verify="required" lay-skin="primary" title="同意"> -->
    <!--  <a href="#terms" target="_blank" style="position: relative; top: 6px; ">-->
    <!--    <ins>同意 [用户协议]</ins>-->
    <!--  </a>-->
    <!--</div>-->
    <div class="layui-form-item">
      <button class="layui-btn layui-btn-fluid" onclick="reg()">注册</button>
    </div>
    <div class="layui-form-item demo-reg-other">
      <a href="/login/login">登录已有帐号</a>
    </div>
  </div>
</div>

<script type="text/javascript">

// 获取当前页面的 URL
    var urlParams = new URLSearchParams(window.location.search);
    // 检查 URL 中是否包含 code 参数
    if (urlParams.has('code')) {
        // 如果包含，则将 code 参数的值设置为输入框的值
        var codeValue = urlParams.get('code');
        $('#yqcode').val(codeValue);
    }

    var mailregs = {:sysconfig('sms','smsstatus')};
	var wat = 60;
    function sendcode(){
        if(mailregs != '1'){ return false}
        if(!$("#account").val()){layer.msg('请输入手机号'); return false}
        let codes = $('#scode').text();
        if(codes == "获取验证码"){
            wat = 60;
            coden();
            $.post("/login/sendcode", {tel:$("#account").val()},
            function(data, status) {
                if (data.code == 1) {
                    layer.msg(data.msg)
                } else {
                    layer.msg(data.msg)
                }
            });
        }
    }
	
	function coden(){
	    $('#scode').text(wat)
	    wat--; 
	    if(wat < 1){
	        $('#scode').text("获取验证码")
	    }else{
	        setTimeout("coden()", 1000); 
	    }
	}
	
	function reg(){
	    let codeval = "0";
	    if(mailregs == "1"){
	        codeval = $("#code").val();
	        if(!codeval){
    	        layer.msg("请输入验证码");
    	        return false;
    	    }
	    }

        $.post("/login/reg", {
            account: $("#account").val(),
            nickname: $("#nickname").val(),
            password: $("#password").val(),
            password2: $("#password2").val(),
            code: codeval,
            yqcode:$("#yqcode").val(),
        },
        function(data, status) {
            if (data.code == 1) {
                layer.msg(data.msg)
                setTimeout(function() {
                    window.location.href = "/login/login"
                },2000);
            } else {
                layer.msg(data.msg)
            }
        });
    }

</script>
 
</body>
</html>